﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace Wimm.CustomContols.PieDiagram
{
    public sealed partial class PieDiagram : UserControl
    {
        private DataVirtualization.Toolkit.DataItemCollection _collection; 

        public PieDiagram()
        {
            this.SizeChanged += PieDiagram_SizeChanged;

            _collection = new DataVirtualization.Toolkit.DataItemCollection();

            _collection.Add(new DataVirtualization.Toolkit.DataItem()
            {
                DataSymbol = "Dollars",
                ID = 1,
                Name = "Food",
                Value = 500
            });
            _collection.Add(new DataVirtualization.Toolkit.DataItem()
            {
                DataSymbol = "Dollars",
                ID = 2,
                Name = "Transport",
                Value = 200
            });
            _collection.Add(new DataVirtualization.Toolkit.DataItem()
            {
                DataSymbol = "Dollars",
                ID = 3,
                Name = "Meetings",
                Value = 300
            });
            _collection.Add(new DataVirtualization.Toolkit.DataItem()
            {
                DataSymbol = "Dollars",
                ID = 4,
                Name = "Water",
                Value = 700
            });

            _collection.Add(new DataVirtualization.Toolkit.DataItem()
            {
                DataSymbol = "Dollars",
                ID = 5,
                Name = "Gas",
                Value = 800
            });

            _collection.Add(new DataVirtualization.Toolkit.DataItem()
            {
                DataSymbol = "Dollars",
                ID = 6,
                Name = "House",
                Value = 700
            });

            _collection.Add(new DataVirtualization.Toolkit.DataItem()
            {
                DataSymbol = "Dollars",
                ID = 7,
                Name = "Transport",
                Value = 700
            });

            _collection.Add(new DataVirtualization.Toolkit.DataItem()
            {
                DataSymbol = "Dollars",
                ID = 8,
                Name = "Cafe",
                Value = 700
            });

            this.InitializeComponent();

            chart.ItemsSource = _collection;
            chart.ItemSelected += chart_ItemSelected;
            chart.ItemDeSelected += chart_ItemDeSelected;

            this.DataContext = this;
        }

        void PieDiagram_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Debug.WriteLine("New height:{0}", e.NewSize.Height);
            Debug.WriteLine("New width:{0}", e.NewSize.Width);

            this.chart.Height = e.NewSize.Height;
            this.chart.Width = e.NewSize.Width;
            this.chart.ItemsSource = null;
            this.chart.ItemsSource = _collection;
        }

        private void chart_ItemDeSelected(object sender, DataVirtualization.Toolkit.DataItem e)
        {
           // txtPageHeader.Text = string.Format("{0} Has been Selected with Value {1}", e.Name, e.Value.ToString());
        }

        private void chart_ItemSelected(object sender, DataVirtualization.Toolkit.DataItem e)
        {
           // txtPageHeader.Text = string.Format("{0} Has been Selected with Value {1}", e.Name, e.Value.ToString());
        }

    }
}
